Field of the Invention
The present disclosure relates to handling cross-thread method calls, and more specifically, to compiling object code for a secondary thread in a multi-threaded runtime environment in a computing system.
Description of the Related Art
A multi-thread runtime environment typically has two or more threads dedicated to specific types of processing. For example, a primary execution thread for performing a central process and a secondary thread for user interactions including updating a graphical user interface showing the progress of the central process and perhaps allowing the user to cancel, pause or control the central process. The central process is performed more efficiently in a dedicated thread when it is isolated from other processes in other threads. While the problem is applicable to two or more threads it can be described with respect to just two threads.
One challenge for multi-threaded runtime environments is that it is often necessary for threads to interact with each other, but if interactions are not handled correctly, then the efficiency of multiple threads is lost. Interactions can involve passing data using a shared data structure, or it can be more complex and involve method calls between threads. An example of marshalling is a first method in the primary thread calling a second method in the secondary thread and waiting for completion of the second method before continuing the first method in the primary thread. Waiting is synchronous marshalling. Another example is where a first method in a primary thread will not wait for a second method in a secondary thread to complete. Not waiting is asynchronous marshalling.
Known computer language libraries provide utility methods to facilitate marshalling a method on a specific thread, for instance a thread dedicated to a graphical user interface. However, the responsibility for marshalling the method is placed on the method and the programmer. This means that the called method must contain code instructions for checking whether it is executing on the correct thread; and if not, the called method must perform marshalling itself. If the number and type of methods that require marshalling is large, then adding correctly formed code to each method becomes cumbersome. If the programmer uses an incorrect syntax then there is increased risk of error when the method is invoked on the wrong thread.